package com.edu.service.task;

import com.edu.common.utils.SpringBeanManager;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 任务管理器
 * 线程池应用步骤3
 */
public class TaskManager {
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
    //private final Mao<String, TaskListener> taskListenerMap = new ConcurrentHashMap<>();

    public TaskManager(ThreadPoolTaskExecutor threadPoolTaskExecutor){
        this.threadPoolTaskExecutor = threadPoolTaskExecutor;
    }
    public  void pushTask(TaskParam taskParam){
        TaskListener taskListener = SpringBeanManager.getBean(taskParam.getTaskListenerClass());
        if(taskListener != null){
            threadPoolTaskExecutor.execute(() -> {
                taskListener.onMessage(taskParam);
            });
        }
    }

}
